package kara;



import java.io.*;
import java.util.LinkedList;
import java.util.Queue;

//代码随想录p100bfs实现
public class A100P4 {
    static int n;
    static int m;
    static int[][] map;
    static int res = 0;
    static int[] dir1 = {1, 0, -1, 0};
    static int[] dir2 = {0, 1, 0, -1};
    static int[][] vis;
    static int ans;
    static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] split = read.readLine().split(" ");
        n = Integer.parseInt(split[0]);
        m = Integer.parseInt(split[1]);
        map = new int[n][m];
        vis=new int[n][m];
        for (int i = 0; i < n; i++) {
            String[] s = read.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                map[i][j] = Integer.parseInt(s[j]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (map[i][j] == 1 && vis[i][j] == 0) {
                    ans = 0;
                    bfs(i, j);
                    res = res >= ans ? res : ans;
                }
            }
        }
        log.write(Integer.toString(res));
        log.flush();
    }

    static class Pair {
        int x;
        int y;
        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    //bfs处理某个岛屿所有陆地
    static void bfs(int x, int y) {
        Queue<Pair> queue = new LinkedList<>();
        vis[x][y] = 1;//标记
        queue.offer(new Pair(x, y));
        while (!queue.isEmpty()) {
            Pair poll = queue.poll();
            ans++;
            int e = poll.x;
            int r = poll.y;
            for (int i = 0; i < 4; i++) {
                int a = e + dir1[i];
                int b = r + dir2[i];
                //合法就标记然后加入队列
                if (a >= 0 && a < n && b >= 0 && b < m && vis[a][b] == 0 && map[a][b] == 1) {
                    vis[a][b] = 1;
                    queue.offer(new Pair(a,b));
                }

            }
        }
    }
}
